// renyuanLocal.js 人员本地存储操作工具，包含人员信息的增删查改等方法
const STORAGE_KEY = 'renyuan';

export function getRenyuanList() {
  return JSON.parse(localStorage.getItem(STORAGE_KEY) || '[]');
}

export function saveRenyuanList(list) {
  localStorage.setItem(STORAGE_KEY, JSON.stringify(list));
}

export function addRenyuan(item) {
  const list = getRenyuanList();
  item.id = Date.now();
  list.push(item);
  saveRenyuanList(list);
}

export function updateRenyuan(item) {
  const list = getRenyuanList();
  const idx = list.findIndex(i => i.id === item.id);
  if (idx !== -1) {
    list[idx] = item;
    saveRenyuanList(list);
  }
}

export function deleteRenyuan(ids) {
  let list = getRenyuanList();
  list = list.filter(i => !ids.includes(i.id));
  saveRenyuanList(list);
}

export function getRenyuanById(id) {
  return getRenyuanList().find(i => i.id === id);
} 